#ifndef SPI_LCD_H_
#define SPI_LCD_H_

#include "lpc213x.h"
#include "system.h"
#include "delay.h"
#include "cpu/spi.h"

//********************************************************************
//
//					LCD Controller
//
//********************************************************************
//#define EPSON
#define PHILLIPS

//********************************************************************
//
//					LCD Dimension Definitions
//
//********************************************************************
#define ROW_LENGTH	132
#define COL_HEIGHT	132
#define ENDPAGE     132
#define ENDCOL      130

//********************************************************************
//
//					LCD Color Depth
//
//********************************************************************
//#define LCD_COLOR_DEPTH_12
#define LCD_COLOR_DEPTH_16

//********************************************************************
//
//					EPSON Controller Definitions
//
//********************************************************************
#ifdef EPSON
#define DISON       0xAF
#define DISOFF      0xAE
#define DISNOR      0xA6
#define DISINV      0xA7
#define SLPIN       0x95
#define SLPOUT      0x94
#define COMSCN      0xBB
#define DISCTL      0xCA
#define PASET       0x75
#define CASET       0x15
#define DATCTL      0xBC
#define RGBSET8     0xCE
#define RAMWR       0x5C
#define RAMRD       0x5D
#define PTLIN       0xA8
#define PTLOUT      0xA9
#define RMWIN       0xE0
#define RMWOUT      0xEE
#define ASCSET      0xAA
#define SCSTART     0xAB
#define OSCON       0xD1
#define OSCOFF      0xD2
#define PWRCTR      0x20
#define VOLCTR      0x81
#define VOLUP       0xD6
#define VOLDOWN     0xD7
#define TMPGRD      0x82
#define EPCTIN      0xCD
#define EPCOUT      0xCC
#define EPMWR       0xFC
#define EPMRD       0xFD
#define EPSRRD1     0x7C
#define EPSRRD2     0x7D
#define NOP         0x25
#endif
//********************************************************************
//
//			PHILLIPS Controller Definitions
//
//********************************************************************
//LCD Commands
#ifdef PHILLIPS
#define	NOPP		0x00
#define	BSTRON		0x03
#define SLEEPIN     0x10
#define	SLEEPOUT	0x11
#define	NORON		0x13
#define	INVOFF		0x20
#define INVON      	0x21
#define	SETCON		0x25
#define DISPOFF     0x28
#define DISPON      0x29
#define CASETP      0x2A
#define PASETP      0x2B
#define RAMWRP      0x2C
#define RGBSET	    0x2D
#define	MADCTL		0x36
#define	COLMOD		0x3A
#define DISCTR      0xB9
#define	EC			0xC0
#endif
//*******************************************************
//				Color Definitions
//*******************************************************
// convierten de RGB(255,255,255) a RGB(bits)
#define RGB323(r,g,b)		(r)
#define RGB444(r,g,b)		((((r*15)/255)<<8)&0x0F00) | ((((g*15)/255)<<4)&0xF0) | (((b*15)/255)&0x0F)
#define RGB565(r,g,b)		(((r>>3)&0x1F)<<10) | (((g>>2)&0x3F)<<5) | ((b>>3)&0x1F)

#ifdef LCD_COLOR_DEPTH_12
#define RGB(r,g,b)			RGB444(r,g,b)
#endif

#ifdef LCD_COLOR_DEPTH_8
#define RGB(r,g,b)			RGB323(r,g,b)
#endif

#ifdef LCD_COLOR_DEPTH_16
#define RGB(r,g,b)			RGB565(r,g,b)
#endif


#define COLOR_WHITE		0xFFFF
#define COLOR_BLACK		0x0000

#ifdef LCD_COLOR_DEPTH_16

	#define COLOR_RED		0xF800
	#define	COLOR_GREEN		0x07E0
	#define COLOR_BLUE		0x001F
	#define COLOR_CYAN		0x07FF
	#define COLOR_MAGENTA	0xF81F
	#define COLOR_YELLOW	0xFFE0

#endif

//********************************************************************
//
//				Low Level API Functions
//
//********************************************************************
void spilcd_ClearScreen(int color);
void inline spilcd_SendCommand(unsigned char data);
void inline spilcd_SendData(unsigned char data);
void spilcd_Init(void);
void spilcd_PutPixel(unsigned int color, unsigned int x, unsigned int y);

#endif /*SPI_LCD_H_*/
